package com.atguigu.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @auther zzyy
 * @create 2024-06-23 11:34
 */
public enum PayTypeStrEnum {
    //多个KV键值对的映射啊，但是 ，它无法处理更多的业务逻辑
    CCB("CCB", 1),
    ABC("ABC", 2),
    CB("CB", 3);

    @Getter
    private String fromCode;
    @Getter
    private Integer toCode;

    PayTypeStrEnum(String fromCode, Integer toCode) {
        this.fromCode = fromCode;
        this.toCode = toCode;
    }


    private static Map<String, PayTypeStrEnum> FROM_CODE_MAP =
            Arrays.stream(PayTypeStrEnum.values())
                    .collect(Collectors.toMap(PayTypeStrEnum::getFromCode, Function.identity()));

    public static PayTypeStrEnum get(String payTypeStr) {
        return FROM_CODE_MAP.get(payTypeStr);
    }

    public static Integer parseCode(String payTypeStr) {
        return Optional.ofNullable(PayTypeStrEnum.get(payTypeStr)).map(PayTypeStrEnum::getToCode).orElse(null);
    }




    /*public static void main(String[] args)
    {
        System.out.println(PayTypeStrEnum.parseCode("ABC"));
    }*/
}
